const express = require('express')
const path = require('path')
const session = require('express-session')
const app = express()

const auth = require("./middlewares/auth")

//引入拆分出去的路由模块
const postRouter = require('./routes/post')
const userRouter = require('./routes/user')


// 使用哪种模板引擎，模板页面的存放路径
app.set('view engine', 'ejs')
app.set('views', path.resolve(__dirname, './views'))

//  req.body的中间件
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

//静态资源托管的设置
app.use(express.static(path.resolve(__dirname, './piblic')))


//设置session中间件
app.use(
    session({
        //选项配置
        resave:true,
        saveUninitialized:true,
        secret:'sdaadad',
        cookie:{
            maxAge:60*1000*24
        }
    })
)



app.use("/posts",auth,postRouter)
app.use(userRouter)
app.listen(8080)